package org.example.ReflectDemo.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Slf4j
@Aspect
@Component
public class TimeRecordAspect {
    @Around("@annotation(org.example.ReflectDemo.aspect.TimeRecord)")
    public Object doAround(ProceedingJoinPoint pjp) throws Throwable {
        long start = System.currentTimeMillis();
        //执行原始方法
        Object result = null;
        try {
            result = pjp.proceed();
        } catch (Throwable e) {
            throw new RuntimeException(e);
        }finally {
            long cost = System.currentTimeMillis() -start;
            log.info(pjp.getSignature() +" 耗时: {} ms", cost);
        }
        return result;
    }
}
